<?php
declare(strict_types=1);

namespace LowCode\Traits\Vue;

trait HasImport
{
    /**
     * @param string ...$names
     * @return $this
     */
    public function addVueImport(string ...$names): static
    {
        if ($names){
            foreach ($names as $name){
                $this->builder->import->add($name);
                $this->variables->add($name);
            }
        }
        return $this;
    }

    /**
     * @param string $import
     * @return $this
     */
    public function addImport(string $import): static
    {
        $this->imports->add($import);
        return $this;
    }

    protected function getImportHtml(): string
    {
        $imports = $this->builder->import->all();
        if ($imports){
            $variable = implode(",", $imports);
            $vueImport = "import { $variable } from \"vue\"";
            $this->imports->unshift($vueImport);
        }
        $values = $this->imports->all();
        return $this->implode($values);
    }
}
